import { ipcMain } from 'electron'

import ScreenRecordingApi from '../api/screenRecording.api'
import { IpcScreenRecordingKeys } from '../../../common/enums/ipc.screenRecording.enum'
export function registerScreenRecordingIpc() {
  // 获取可用的屏幕源
  ipcMain.handle(IpcScreenRecordingKeys.GET_SOURCES, async () => {
    return ScreenRecordingApi.getSources()
  })

  // 开始录制
  ipcMain.handle(IpcScreenRecordingKeys.START_RECORDING, async (_, options) => {
    return ScreenRecordingApi.startRecording(options)
  })

  // 暂停录制
  ipcMain.handle(IpcScreenRecordingKeys.PAUSE_RECORDING, async (_, recorderId) => {
    return ScreenRecordingApi.pauseRecording(recorderId)
  })

  // 继续录制
  ipcMain.handle(IpcScreenRecordingKeys.REGION_CANCELED, async (_, recorderId) => {
    return ScreenRecordingApi.resumeRecording(recorderId)
  })

  // 停止录制
  ipcMain.handle(IpcScreenRecordingKeys.STOP_RECORDING, async (_, recorderId) => {
    return ScreenRecordingApi.stopRecording(recorderId)
  })

  // 全屏截图
  ipcMain.handle(IpcScreenRecordingKeys.TAKE_FULL_SCREEN_SHOT, async (_, options) => {
    return ScreenRecordingApi.takeFullScreenshot(options)
  })

  // 区域截图
  ipcMain.handle(IpcScreenRecordingKeys.TAKE_REGION_SCREEN_SHOT, async () => {
    return ScreenRecordingApi.takeRegionScreenshot()
  })
}
